//
//  LXDChartsTableViewCell.m
//  BLDMusics
//
//  Created by lxd on 16/3/17.
//  Copyright © 2016年 李晓丹. All rights reserved.
//

#import "LXDChartsTableViewCell.h"
#import "UIImageView+WebCache.h"

// 宏
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGTH [UIScreen mainScreen].bounds.size.height
@implementation LXDChartsTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
    }
    return self;
}


- (void)createCell {
    
    self.image = [[UIImageView alloc] init];
    [self.contentView addSubview:_image];
    
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_titleLabel];
    
    self.firstSong = [[UILabel alloc] init];
    [self.contentView addSubview:_firstSong];
    _firstSong.font = [UIFont systemFontOfSize:15];
    _firstSong.textColor = [UIColor darkGrayColor];
    
    self.secondSong = [[UILabel alloc] init];
    [self.contentView addSubview:_secondSong];
    _secondSong.font = [UIFont systemFontOfSize:15];
    _secondSong.textColor = [UIColor darkGrayColor];
    
    self.thirdSong = [[UILabel alloc] init];
    [self.contentView addSubview:_thirdSong];
    _thirdSong.font = [UIFont systemFontOfSize:15];
    _thirdSong.textColor = [UIColor darkGrayColor];
}


- (void)layoutSubviews {
    [super layoutSubviews];
    
    _image.frame = CGRectMake(15, 10, (SCREEN_WIDTH - 30) / 3, (SCREEN_WIDTH - 30) / 3);
    
    _titleLabel.frame = CGRectMake(10 + _image.frame.size.width + 15, _image.frame.origin.y + 5, SCREEN_WIDTH - 45 - _image.frame.size.width, 20);
    
    CGFloat height = _image.frame.size.height;
    
    _firstSong.frame = CGRectMake(10 + _image.frame.size.width + 15, _titleLabel.frame.origin.y + 5 + 20, SCREEN_WIDTH - 45 - _image.frame.size.width, (height - 45) / 3);
    
    _secondSong.frame = CGRectMake(10 + _image.frame.size.width + 15, _firstSong.frame.origin.y + _firstSong.frame.size.height + 5, SCREEN_WIDTH - 45 - _image.frame.size.width, (height - 45) / 3);
    
    _thirdSong.frame = CGRectMake(10 + _image.frame.size.width + 15, _secondSong.frame.origin.y + _secondSong.frame.size.height + 5, SCREEN_WIDTH - 45 - _image.frame.size.width, (height - 45) / 3);
    
}


- (void)setModel:(LXDChartsModel *)model {
    _model = model;
    [self assignControl];
}

- (void)assignControl {
    _titleLabel.text = self.model.title;
    [_image sd_setImageWithURL:[NSURL URLWithString:self.model.pic]];
    
    NSArray *tempArr = [NSArray arrayWithArray:self.model.songsArray];
    LXDChartsModel *model1 = tempArr[0];
    LXDChartsModel *model2 = tempArr[1];
    LXDChartsModel *model3 = tempArr[2];
        
    _firstSong.text = [NSString stringWithFormat:@"1.%@ %@", model1.name, model1.singerName];
    _secondSong.text = [NSString stringWithFormat:@"2.%@ %@", model2.name, model2.singerName];
   _thirdSong.text = [NSString stringWithFormat:@"3.%@ %@", model3.name, model3.singerName];
    
    
    
}

@end
